package com.itheima.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.HmQuestionsAuditsMapper;
import com.itheima.mapper.FrameMapper;
import com.itheima.pojo.BsUser;
import com.itheima.pojo.hm.AuditOpinions;
import com.itheima.pojo.hm.HmQuestionsAudits;
import com.itheima.service.HmQuestionsAuditsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HmQuestionsAuditsServiceImpl implements HmQuestionsAuditsService {
    @Autowired
    private HmQuestionsAuditsMapper hmQuestionsAuditsMapper;
    @Autowired
    private FrameMapper userMapper;

    @Override
    public Object[] auditOpinions(Integer id) {//问题id
        LambdaQueryWrapper<HmQuestionsAudits> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HmQuestionsAudits::getQuestionsId, id);
        List<HmQuestionsAudits> hmQuestionsAudits = hmQuestionsAuditsMapper.selectList(wrapper);

        Object[] objects = new Object[hmQuestionsAudits.size()];

        for (int i = 0; i < hmQuestionsAudits.size(); i++) {
            AuditOpinions auditOpinions = new AuditOpinions();
            auditOpinions.setOpinion(hmQuestionsAudits.get(i).getRemarks());
            auditOpinions.setChkTime(hmQuestionsAudits.get(i).getChkTime().toString());
            BsUser bsUser = userMapper.selectById(hmQuestionsAudits.get(i).getCheckerId());
            auditOpinions.setChecker(bsUser.getUsername());
            for (int j = -1; j < i; j++) {
                objects[i] = auditOpinions;
            }
        }
        return objects;
    }
}
